package com.thoughtworks;

import sun.misc.BASE64Encoder;

import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by cmi on 7/23/14.
 * driven by DatabaseTest.
 */
public class Database {

    public Database(String arg) {
        this(arg,false);
    }
    public Database(String arg, boolean test) {
        String folderPath;
        if(test) {
            folderPath = "./dataTest/"+arg;
        } else {
            folderPath = "./data/"+arg;
        }
        File file = new File(folderPath);
        try {
            if(file.createNewFile()) {
                //new database
            } else {
                //load database
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private String MD5(String pwd)
    {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        BASE64Encoder base = new BASE64Encoder();
        if(md == null) {
            return null;
        } else {
            return base.encode(md.digest(pwd.getBytes()));
        }
    }

    public boolean Login(String user,String password){
        return true;
    }
}
